package android.framework.util;

/** 
 * @ClassName: UIs 
 * @Description: TODO 
 * @author jtf19@163.com
 * @date 2013-5-28 ����3:44:29 
 *  
 */
import java.util.Calendar;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.framework.App;
import android.framework.app.MainActivity;
import android.framework.widget.CustomToast;
import android.os.BatteryManager;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import android.framework.R;

public class UIs {
	private static String TAG = UIs.class.getSimpleName();
	private static CustomToast cToast = null;
	private static Toast sysToast = null;

	public static void call(Activity paramActivity, int paramInt1,
			int paramInt2, int paramInt3,
			DialogInterface.OnClickListener paramOnClickListener1,
			DialogInterface.OnClickListener paramOnClickListener2) {
		if (paramActivity == null)
			return;
		AlertDialog localAlertDialog = new AlertDialog.Builder(paramActivity)
				.setTitle(2131296618).setIcon(2130837633).setMessage(paramInt1)
				.setPositiveButton(paramInt2, paramOnClickListener1)
				.setNegativeButton(paramInt3, paramOnClickListener2).create();
		if ((paramActivity.isFinishing()) || (paramActivity.isRestricted()))
			localAlertDialog.show();
	}

	public static void call(Activity paramActivity, int paramInt1,
			int paramInt2, int paramInt3,
			DialogInterface.OnClickListener paramOnClickListener1,
			DialogInterface.OnClickListener paramOnClickListener2,
			View paramView) {
		if (paramActivity == null)
			return;
		AlertDialog localAlertDialog = new AlertDialog.Builder(paramActivity)
				.setTitle(2131296618).setIcon(2130837633).setMessage(paramInt1)
				.setView(paramView)
				.setPositiveButton(paramInt2, paramOnClickListener1)
				.setNegativeButton(paramInt3, paramOnClickListener2).create();
		if ((paramActivity.isFinishing()) || (paramActivity.isRestricted()))
			localAlertDialog.show();
	}

	public static void call(Activity paramActivity, int paramInt1,
			int paramInt2, int paramInt3,
			DialogInterface.OnClickListener paramOnClickListener1,
			DialogInterface.OnClickListener paramOnClickListener2,
			boolean paramBoolean) {
		if (paramActivity == null)
			return;
		AlertDialog localAlertDialog = new AlertDialog.Builder(paramActivity)
				.setMessage(paramInt1).setCancelable(paramBoolean)
				.setPositiveButton(paramInt2, paramOnClickListener1)
				.setNegativeButton(paramInt3, paramOnClickListener2).create();
		if ((paramActivity.isFinishing()) || (paramActivity.isRestricted()))
			localAlertDialog.show();
	}

	public static void call(Activity paramActivity, int paramInt1,
			int paramInt2, int paramInt3,
			DialogInterface.OnClickListener paramOnClickListener,
			boolean paramBoolean) {
		if (paramActivity == null)
			return;
		AlertDialog localAlertDialog = new AlertDialog.Builder(paramActivity)
				.setTitle(paramInt1).setIcon(2130837633).setMessage(paramInt2)
				.setCancelable(paramBoolean)
				.setPositiveButton(paramInt3, paramOnClickListener).create();
		if ((paramActivity.isFinishing()) || (paramActivity.isRestricted()))
			localAlertDialog.show();
	}

	public static void call(Activity paramActivity, int paramInt1,
			int paramInt2,
			DialogInterface.OnClickListener paramOnClickListener1,
			DialogInterface.OnClickListener paramOnClickListener2) {
		if (paramActivity == null)
			return;
		AlertDialog localAlertDialog = new AlertDialog.Builder(paramActivity)
				.setTitle(paramInt1).setIcon(2130837633).setMessage(paramInt2)
				.setPositiveButton(2131296619, paramOnClickListener1)
				.setNegativeButton(2131296620, paramOnClickListener2).create();
		if ((paramActivity.isFinishing()) || (paramActivity.isRestricted()))
			localAlertDialog.show();
	}

	public static void call(Activity paramActivity, int paramInt,
			DialogInterface.OnClickListener paramOnClickListener) {
		if (paramActivity == null)
			return;
		AlertDialog localAlertDialog = new AlertDialog.Builder(paramActivity)
				.setTitle(2131296618).setIcon(2130837633).setMessage(paramInt)
				.setPositiveButton(2131296619, paramOnClickListener).create();
		if ((paramActivity.isFinishing()) || (paramActivity.isRestricted()))
			localAlertDialog.show();
	}

	public static void call(Activity paramActivity, int paramInt,
			DialogInterface.OnClickListener paramOnClickListener1,
			DialogInterface.OnClickListener paramOnClickListener2) {
		if (paramActivity == null)
			return;
		AlertDialog localAlertDialog = new AlertDialog.Builder(paramActivity)
				.setTitle(2131296618).setIcon(2130837633).setMessage(paramInt)
				.setPositiveButton(2131296619, paramOnClickListener1)
				.setNegativeButton(2131296620, paramOnClickListener2).create();
		if ((paramActivity.isFinishing()) || (paramActivity.isRestricted()))
			try {
				localAlertDialog.show();
			} catch (Exception localException) {
				localException.printStackTrace();
			}
	}

	public static void call(Activity paramActivity, String paramString,
			DialogInterface.OnClickListener paramOnClickListener) {
		if (paramActivity == null)
			return;
		AlertDialog localAlertDialog = new AlertDialog.Builder(paramActivity)
				.setTitle(2131296618).setIcon(2130837633)
				.setMessage(paramString)
				.setPositiveButton(2131296619, paramOnClickListener).create();
		if ((paramActivity.isFinishing()) || (paramActivity.isRestricted()))
			localAlertDialog.show();
	}

	public static void call(Activity paramActivity, String paramString,
			DialogInterface.OnClickListener paramOnClickListener,
			boolean paramBoolean) {
		if (paramActivity == null)
			return;
		AlertDialog localAlertDialog = new AlertDialog.Builder(paramActivity)
				.setTitle(2131296618).setIcon(2130837633)
				.setMessage(paramString)
				.setPositiveButton(2131296619, paramOnClickListener).create();
		localAlertDialog.setCancelable(paramBoolean);
		if ((paramActivity.isFinishing()) || (paramActivity.isRestricted()))
			localAlertDialog.show();
	}

	public static void call(Context paramContext, int paramInt1, int paramInt2,
			int paramInt3,
			DialogInterface.OnClickListener paramOnClickListener1,
			DialogInterface.OnClickListener paramOnClickListener2,
			boolean paramBoolean) {
		if (paramContext == null)
			return;
		AlertDialog localAlertDialog = new AlertDialog.Builder(paramContext)
				.setTitle(2131296959).setIcon(2130837633).setMessage(paramInt1)
				.setCancelable(paramBoolean)
				.setPositiveButton(paramInt2, paramOnClickListener1)
				.setNegativeButton(paramInt3, paramOnClickListener2).create();
		if ((!(paramContext instanceof Activity))
				|| (((Activity) paramContext).isFinishing())
				|| (paramContext.isRestricted()))
			localAlertDialog.show();
	}

	public static void call(Context paramContext, String paramString1,
			String paramString2, int paramInt1, int paramInt2,
			DialogInterface.OnClickListener paramOnClickListener1,
			DialogInterface.OnClickListener paramOnClickListener2,
			boolean paramBoolean) {
		if (paramContext == null)
			return;
		AlertDialog localAlertDialog = new AlertDialog.Builder(paramContext)
				.setTitle(paramString1).setIcon(2130837633)
				.setMessage(paramString2).setCancelable(paramBoolean)
				.setPositiveButton(paramInt1, paramOnClickListener1)
				.setNegativeButton(paramInt2, paramOnClickListener2).create();
		if ((!(paramContext instanceof Activity))
				|| (((Activity) paramContext).isFinishing())
				|| (paramContext.isRestricted()))
			localAlertDialog.show();
	}

	public static boolean call(Activity paramActivity, int paramInt1,
			int paramInt2, int paramInt3,
			DialogInterface.OnClickListener paramOnClickListener1,
			DialogInterface.OnClickListener paramOnClickListener2,
			View paramView, boolean paramBoolean) {
		if (paramActivity == null)
			return false;
		AlertDialog localAlertDialog = new AlertDialog.Builder(paramActivity)
				.setTitle(2131296618).setIcon(2130837633).setMessage(paramInt1)
				.setCancelable(paramBoolean).setView(paramView)
				.setPositiveButton(paramInt2, paramOnClickListener1)
				.setNegativeButton(paramInt3, paramOnClickListener2).create();
		if ((paramActivity.isFinishing()) || (paramActivity.isRestricted()))
			localAlertDialog.show();
		return true;
	}

	public static void cancelNotify() {
		if (cToast != null)
			cToast.cancel();
		if (sysToast == null)
			return;
		sysToast.cancel();
	}

	public static void changeBatteryState(int paramInt1, int paramInt2,
			View paramView) {
		if (paramView != null) {
			switch (paramInt1) {
			case BatteryManager.BATTERY_STATUS_UNKNOWN:
				if (paramInt2 >= 80)
					paramView.setBackgroundResource(R.drawable.battery5);
				break;
			case BatteryManager.BATTERY_STATUS_DISCHARGING:
				if (paramInt2 >= 60)
					paramView.setBackgroundResource(R.drawable.battery4);
				break;
			case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
				if (paramInt2 >= 40)
					paramView.setBackgroundResource(R.drawable.battery3);
				break;
			case BatteryManager.BATTERY_STATUS_FULL:
				if (paramInt2 >= 20)
					paramView.setBackgroundResource(R.drawable.battery2);
				break;
			case BatteryManager.BATTERY_STATUS_CHARGING:
				paramView.setBackgroundResource(R.drawable.battery_charge);
				break;
			default:
				if (paramInt2 < 0)
					paramView.setBackgroundResource(R.drawable.battery1);
				break;
			}
		}
	}

	public static void changeNetState(Context paramContext, View paramView) {
		if (paramView != null)
			switch (NetWorkTypeUtils.getNetType(paramContext)) {
			default:
			case 0:
				paramView.setBackgroundResource(R.drawable.net_no);
				break;
			case 1:
				paramView.setBackgroundResource(R.drawable.net_wifi);
				break;
			case 2:
				paramView.setBackgroundResource(R.drawable.net_2g);
				break;
			case 3:
				paramView.setBackgroundResource(R.drawable.net_3g);
				break;
			}
	}

	public static void changeSoundState(int paramInt1, int paramInt2,
			ImageView paramImageView) {
		if (paramImageView != null) {
			if (paramInt1 < 2 * (paramInt2 / 3))
				paramImageView.setImageResource(2130837978);
			else {
				if (paramInt1 >= paramInt2 / 3)
					paramImageView.setImageResource(2130837979);
				if (paramInt1 > 0)
					paramImageView.setImageResource(2130837973);
			}
			paramImageView.setImageResource(2130837980);
		}
	}

	public static void changeTimeState(TextView paramTextView) {
		if (paramTextView == null)
			return;
		Calendar localCalendar = Calendar.getInstance();
		localCalendar.setTimeInMillis(System.currentTimeMillis());
		int i = localCalendar.get(Calendar.HOUR_OF_DAY);
		L.i("&&&&&&  " + i);
		int j = localCalendar.get(Calendar.MINUTE);
		L.i("&&&&&&  " + j);
		paramTextView.setText(getStringTwo(String.valueOf(i)) + ":"
				+ getStringTwo(String.valueOf(j)));
	}

	public static String getStringTwo(String paramString) {
		if (paramString.length() < 2)
			paramString = "0".concat(paramString);
		return paramString;
	}

	public static void createShortCutIcon(Context paramContext) {
		Intent localIntent1 = new Intent("android.intent.action.MAIN");
		localIntent1.setClass(paramContext, MainActivity.class);
		localIntent1.addCategory("android.intent.category.LAUNCHER");
		localIntent1.addFlags(268435456);
		localIntent1.addFlags(2097152);
		Intent localIntent2 = new Intent();
		localIntent2.putExtra("android.intent.extra.shortcut.INTENT",
				localIntent1);
		localIntent2.putExtra("android.intent.extra.shortcut.NAME",
				paramContext.getResources().getString(2131296256));
		localIntent2.putExtra(
				"android.intent.extra.shortcut.ICON_RESOURCE",
				Intent.ShortcutIconResource.fromContext(
						paramContext.getApplicationContext(), 2130837690));
		localIntent2.putExtra("duplicate", false);
		localIntent2.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
		paramContext.sendBroadcast(localIntent2);
	}

	public static void deleteShortCutIcon(Context paramContext) {
		Intent localIntent1 = new Intent("android.intent.action.MAIN");
		localIntent1.addCategory("android.intent.category.LAUNCHER");
		localIntent1.addFlags(268435456);
		localIntent1.addFlags(2097152);
		Intent localIntent2 = new Intent();
		localIntent2
				.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
		localIntent2.putExtra("android.intent.extra.shortcut.INTENT",
				localIntent1);
		paramContext.sendBroadcast(localIntent2);
	}

	public static int dipToPx(Context paramContext, int paramInt) {
		if (paramContext == null) {
			paramContext = App.getInstance().getApplicationContext();
		}
		paramInt = (int) (0.5F + paramContext.getResources()
				.getDisplayMetrics().density * paramInt);
		return paramInt;
	}

	public static float dipToPxFloat(Context paramContext, int paramInt) {
		float f;
		if (paramContext == null) {
			paramContext = App.getInstance().getApplicationContext();
		}
		f = paramContext.getResources().getDisplayMetrics().density * paramInt;
		return f;
	}

	public static int getScreenWidth(Context paramContext) {
		return ((WindowManager) paramContext.getSystemService("window"))
				.getDefaultDisplay().getWidth();
	}

	public static void hideSoftkeyboard(Activity paramActivity) {
		if ((paramActivity == null)
				|| (paramActivity.getCurrentFocus() == null))
			return;
		InputMethodManager localInputMethodManager = (InputMethodManager) paramActivity
				.getSystemService("input_method");
		if (localInputMethodManager == null)
			return;
		localInputMethodManager.hideSoftInputFromWindow(paramActivity
				.getCurrentFocus().getWindowToken(), 2);
	}

	public static View inflate(Context paramContext, int paramInt,
			ViewGroup paramViewGroup) {
		return LayoutInflater.from(paramContext).inflate(paramInt,
				paramViewGroup);
	}

	public static View inflate(Context paramContext, int paramInt,
			ViewGroup paramViewGroup, boolean paramBoolean) {
		return LayoutInflater.from(paramContext).inflate(paramInt,
				paramViewGroup, paramBoolean);
	}

	public static void notifyErrLong(Context paramContext, int paramInt) {
		if ((cToast == null) && (App.getInstance() != null)) {
			cToast = new CustomToast(App.getInstance());
			cToast.setDuration(1);
		}
		cToast.setErr(true);
		cToast.setMsg(paramInt);
		cToast.show();
	}

	public static void notifyErrLong(Context paramContext, String paramString) {
		if ((cToast == null) && (App.getInstance() != null)) {
			cToast = new CustomToast(App.getInstance());
			cToast.setDuration(1);
		}
		cToast.setErr(true);
		cToast.setMsg(paramString);
		cToast.show();
	}

	public static void notifyErrShort(Context paramContext, int paramInt) {
		if ((cToast == null) && (App.getInstance() != null)) {
			cToast = new CustomToast(App.getInstance());
			cToast.setDuration(0);
		}
		cToast.setErr(true);
		cToast.setMsg(paramInt);
		cToast.show();
	}

	public static void notifyErrShort(Context paramContext, String paramString) {
		if ((cToast == null) && (App.getInstance() != null)) {
			cToast = new CustomToast(App.getInstance());
			cToast.setDuration(0);
		}
		cToast.setErr(true);
		cToast.setMsg(paramString);
		cToast.show();
	}

	public static void notifyLong(Context paramContext, int paramInt) {
		if ((cToast == null) && (App.getInstance() != null)) {
			cToast = new CustomToast(App.getInstance());
			cToast.setDuration(1);
		}
		cToast.setErr(false);
		cToast.setMsg(paramInt);
		cToast.show();
	}

	public static void notifyLong(Context paramContext, String paramString) {
		if ((cToast == null) && (App.getInstance() != null)) {
			cToast = new CustomToast(App.getInstance());
			cToast.setDuration(1);
		}
		cToast.setErr(false);
		cToast.setMsg(paramString);
		cToast.show();
	}

	public static void notifyLongNormal(Context paramContext, int paramInt) {
		if ((sysToast == null) && (App.getInstance() != null))
			sysToast = Toast.makeText(App.getInstance(), "", 0);
		sysToast.setDuration(1);
		sysToast.setText(paramInt);
		sysToast.show();
	}

	public static void notifyLongNormal(Context paramContext, String paramString) {
		if ((sysToast == null) && (App.getInstance() != null))
			sysToast = Toast.makeText(App.getInstance(), "", 0);
		sysToast.setDuration(1);
		sysToast.setText(paramString);
		sysToast.show();
	}

	public static void notifyShort(Context paramContext, int paramInt) {
		if ((cToast == null) && (App.getInstance() != null)) {
			cToast = new CustomToast(App.getInstance());
			cToast.setDuration(0);
		}
		cToast.setErr(false);
		cToast.setMsg(paramInt);
		cToast.show();
	}

	public static void notifyShort(Context paramContext, String paramString) {
		if ((cToast == null) && (App.getInstance() != null)) {
			cToast = new CustomToast(App.getInstance());
			cToast.setDuration(0);
		}
		cToast.setErr(false);
		cToast.setMsg(paramString);
		cToast.show();
	}

	public static void notifyShortNormal(Context paramContext, int paramInt) {
		if ((sysToast == null) && (App.getInstance() != null))
			sysToast = Toast.makeText(App.getInstance(), "", 0);
		sysToast.setDuration(0);
		sysToast.setText(paramInt);
		sysToast.show();
	}

	public static void notifyShortNormal(Context paramContext,
			String paramString) {
		if ((sysToast == null) && (App.getInstance() != null))
			sysToast = Toast.makeText(App.getInstance(), "", 0);
		sysToast.setDuration(0);
		sysToast.setText(paramString);
		sysToast.show();
	}

	public static void notifyTiming(Context paramContext, int paramInt1,
			int paramInt2) {
		if ((cToast == null) && (App.getInstance() != null)) {
			cToast = new CustomToast(App.getInstance());
			cToast.setDuration(1);
		}
		cToast.setErr(false);
		cToast.setMsg(paramInt1);
		cToast.show();
		Handler handler = new Handler() {
			public void handleMessage(Message paramMessage) {
				UIs.cToast.cancel();
			}
		};
		cToast.show();
		handler.sendEmptyMessageDelayed(0, paramInt2);
	}

	public static void notifyTiming(Context paramContext, String paramString,
			int paramInt) {
		if ((cToast == null) && (App.getInstance() != null)) {
			cToast = new CustomToast(App.getInstance());
			cToast.setDuration(1);
		}
		cToast.setErr(false);
		cToast.setMsg(paramString);
		cToast.show();
		Handler handler = new Handler() {
			public void handleMessage(Message paramMessage) {
				UIs.cToast.cancel();
			}
		};
		cToast.show();
		handler.sendEmptyMessageDelayed(0, paramInt);
	}

	public static int pxToDip(Context paramContext, float paramFloat) {
		if (paramContext == null) {
			paramContext = App.getInstance().getApplicationContext();
		}
		int i;
		i = (int) (0.5F + paramFloat
				/ paramContext.getResources().getDisplayMetrics().density);
		return i;
	}

	public static void setFullscreenCompatibility(Activity paramActivity) {
	}

	public static void showSoftKeyboard(Activity paramActivity) {
		InputMethodManager localInputMethodManager = (InputMethodManager) paramActivity
				.getSystemService("input_method");
		if (paramActivity.getCurrentFocus() != null)
			localInputMethodManager.showSoftInput(
					paramActivity.getCurrentFocus(), 2);
		localInputMethodManager.toggleSoftInput(0, 2);
	}
}
